import axios from "axios";
import { isMarkId, isToken } from '@/tools/local'
let apiRequest = axios.create({
    baseURL: '/api',
    timeout: 5000
})

apiRequest.interceptors.request.use((config) => {
    let key = isMarkId()
    let isTokenNow = isToken()
    if (config.headers) {
        if (key.value) {
            config.headers.userTempId = key.value as string
        }
        if (isTokenNow) {
            config.headers.token = localStorage.getItem('token') as string
        }
    }
    return config
})
apiRequest.interceptors.response.use((data) => data.data, err => Promise.reject(new Error(err)))

export default apiRequest